﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace UselessExplorer.UI
{
    public partial class ucPreferencesTab : UserControl
    {
        private static ucPreferencesTab instance;
        public static ucPreferencesTab Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new ucPreferencesTab();
                }
                return instance;
            }
        }

        private DevComponents.DotNetBar.TabControl m_MainUITabs = null;

        public ucPreferencesTab ()
        {
            InitializeComponent();
        }

        public void LoadTabDataInPreference ( DevComponents.DotNetBar.TabControl tabCtrl )
        {
            m_MainUITabs = tabCtrl;

            List<string> tabs = new List<string>();
            for (int index = 0; index < m_MainUITabs.Tabs.Count; index++)
            {
                if (!m_MainUITabs.Tabs[index].Text.Equals( "Prefrences" ))
                    tabs.Add( m_MainUITabs.Tabs[index].Text );
            }

            AddDataToUI( tabs );
        }

        private void AddDataToUI ( List<string> tabs )
        {
            lbActiveTabs.Items.Clear();

            foreach (string tab in tabs)
                lbActiveTabs.Items.Add( tab );
        }

        private void btnAddToInactive_Click ( object sender, EventArgs e )
        {
            string SelectedTab = lbActiveTabs.SelectedItem.ToString();

            if (lbActiveTabs.SelectedItem != null)
            {
                for (int index = 0; index < m_MainUITabs.Tabs.Count; index++)
                {
                    if (m_MainUITabs.Tabs[index].Text.Equals( SelectedTab ))
                    {
                        m_MainUITabs.Tabs[index].Visible = false;
                        break;
                    }
                }

                lbInactiveTabs.Items.Add( SelectedTab );
                lbActiveTabs.Items.Remove( SelectedTab );
            }
            else
            {
                MessageBox.Show( "Please Select a tab" );
            }
        }

        private void btnAddToActive_Click ( object sender, EventArgs e )
        {
            string SelectedTab = lbInactiveTabs.SelectedItem.ToString();

            if (lbInactiveTabs.SelectedItem != null)
            {
                for (int index = 0; index < m_MainUITabs.Tabs.Count; index++)
                {
                    if (m_MainUITabs.Tabs[index].Text.Equals( SelectedTab ))
                    {
                        m_MainUITabs.Tabs[index].Visible = true;
                        break;
                    }
                }

                lbActiveTabs.Items.Add( SelectedTab );
                lbInactiveTabs.Items.Remove( SelectedTab );
            }
            else
            {
                MessageBox.Show( "Please Select a tab" );
            }
        }

    }
}
